package org.ycx.doc.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.ycx.doc.dao.auto.DocGroupSqlProvider;
import org.ycx.doc.dao.auto.DocProjectMapper;
import org.ycx.doc.dao.model.DocProject;

import java.util.List;

/**
 * DocProject 自定义Mapper
 * Created by yang on 2017-08-30 17:02:41.
 */
public interface IDocProjectMapper extends DocProjectMapper {

    //    @Select("select dp.* from doc_group dg,doc_group_project dgp,doc_group_user dgu,doc_project dp where dg.GROUP_ID = dgu.GROUP_ID and dgp.GROUP_ID = dg.GROUP_ID and dgp.APP_ID=dp.APP_ID and dgu.USER_ID=#{uid}")
    @Results({
            @Result(column = "APP_ID", property = "appId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "APP_NAME", property = "appName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "APP_DESC", property = "appDesc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "APP_PROD_VERSION", property = "appProdVersion", jdbcType = JdbcType.INTEGER),
            @Result(column = "CREATE_TS", property = "createTs", jdbcType = JdbcType.DATE),
            @Result(column = "CREATE_UID", property = "createUid", jdbcType = JdbcType.INTEGER),
            @Result(column = "UPDATE_TS", property = "updateTs", jdbcType = JdbcType.DATE),
            @Result(column = "UPDATE_UID", property = "updateUid", jdbcType = JdbcType.INTEGER)
    })
    @SelectProvider(type = IDocGroupSqlProvider.class, method = "findProjectByUserProvider")
    List<DocProject> findProjectByUser(@Param("uid") int uid, @Param("rids") List<Integer> rids);

    @Results({
            @Result(column = "APP_ID", property = "appId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "APP_NAME", property = "appName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "APP_DESC", property = "appDesc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "APP_PROD_VERSION", property = "appProdVersion", jdbcType = JdbcType.INTEGER),
            @Result(column = "CREATE_TS", property = "createTs", jdbcType = JdbcType.DATE),
            @Result(column = "CREATE_UID", property = "createUid", jdbcType = JdbcType.INTEGER),
            @Result(column = "UPDATE_TS", property = "updateTs", jdbcType = JdbcType.DATE),
            @Result(column = "UPDATE_UID", property = "updateUid", jdbcType = JdbcType.INTEGER)
    })
    @Select("select dp.* from doc_group_project dgp,doc_project dp where dp.APP_ID = dgp.APP_ID and dgp.GROUP_ID=#{gid}")
    List<DocProject> findProjectByGid(@Param("gid") Integer gid);

    @Select("select role from doc_group_user dgu,doc_group_project dgp where dgp.GROUP_ID = dgu.GROUP_ID and dgp.APP_ID=#{appId} and dgu.USER_ID=#{uid}")
    Integer findRoleByAppAndUid(@Param("appId") Integer appId, @Param("uid") int uid);
}